package tech.yangzhijie.basic.demo02;

import com.alibaba.fastjson.JSONObject;

import org.junit.Before;
import org.junit.Test;
import tech.yangzhijie.basic.demo02.java8.LargeAnimal;
import tech.yangzhijie.basic.demo02.java8.LargeAnimalImpl;
import tech.yangzhijie.basic.demo02.util.MD5Utils;
import tech.yangzhijie.basic.demo02.util.RiskEncryptUtils;

import java.io.File;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

public class Tests {

    @Before
    public void before(){

    }

    @Test
    public void method01(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime of = LocalDateTime.of(2018, 12, 31, 23, 59, 59);
        LocalDateTime of2 = LocalDateTime.of(2017, 12, 31, 23, 59, 59);

        Duration between = Duration.between(now, of);
        long l = between.toDays();
        System.out.println(l);

        Duration between2 = Duration.between(of2, of);
        System.out.println("2018年："+between2.toDays());
    }

    @Test
    public void method(){
        /*BlackListService service = new BlackListServiceImpl();
        //BlackList blackList = service.getBlackList("白杨", "1", "150428198210100032", "15849180482", "");
        BlackList blackList = service.getBlackList("杨志杰", "1", "429006199609218719", "15927108772", "");
        System.out.println(blackList);*/
    }

    @Test
    public void method02(){
        System.out.println(System.currentTimeMillis());
        System.out.println(LocalDateTime.now());

        HashMap<String,Object> map = new HashMap<>();
        map.put("1","a");
    }

    @Test
    public void method03() throws Exception {
        /*BlackList blackList = new BlackList();
        blackList.setId(1);
        Class<? extends BlackList> aClass = blackList.getClass();
        Field id = aClass.getDeclaredField("id");
        id.setAccessible(true);
        Integer anInt = (int)id.get(blackList);
        System.out.println(anInt);*/
    }

    @Test
    public void method04() throws Exception {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        System.out.println(list);
        String substring1 = list.toString().substring(1, list.toString().length() - 1);
        System.out.println(substring1);

    }

    @Test
    public void method05() throws Exception {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        List<String> list2 = new ArrayList<>();
        list2.add("1");
        list2.add("2");
        list2.add("3");
        list2.add("4");

        System.out.println(list.equals(list2));
    }

    @Test
    public void method06(){
        System.out.println(1460+1460+1752);
    }

    @Test
    public void method07() {

        File file = new File("D:\\admin\\文档\\年歌.txt");
        System.out.println(file.getName());
        System.out.println(file.getPath());
        System.out.println(file.getParent());
        System.out.println(file.length());
    }

    @Test
    public void method08() {
        int initNum = 9;
        int res = 0;
        for (int i = 1; i <= initNum; i++) {
            for (int k=1;k<i;k++){
                System.out.print("        ");
            }
            for (int j = i; j <= initNum; j++) {
                res = i*j;
                printFormat(i, j, res);
            }
            System.out.println();
        }
    }

    private void printFormat(int i,int j,int res){
        System.out.printf("%d*%d=%d\t",i,j,res);
    }

    @Test
    public void method9() {
        System.out.println("method9 start");
        //abc(2);
        System.out.println("method9 end");
    }

    private void abc(int i){
        System.out.println("abc start");
        if(i > 0){
            throw new RuntimeException("abc Exception");
        }
        System.out.println("abc end");

    }

    @Test
    public void method10() {
        for (int i = 0; i < 3; i++) {
            System.out.println(UUID.randomUUID().toString().replaceAll("-", "").toUpperCase());
        }

    }

    @Test
    public void name() {
        List<String> names = new ArrayList<>();
        names.add("1");
        names.add("2");
        names.add("3");
        names.add("4");

        StringBuffer s = new StringBuffer();
        for (String name : names) {
            s.append(name).append(",");
        }
        System.out.println(s.toString().substring(0, s.length()-1));
    }

    @Test
    public void name01() {
        for(int i=0;i<4;i++){
            for (int j=0;j<i;j++){
                System.out.print("\t");
            }
            for (int k=0;k<7-2*i;k++){
                System.out.print("*\t");
            }
            System.out.println();
        }
        for(int i=0;i<3;i++){
            for (int j=2;j>i;j--){
                System.out.print("\t");
            }
            for (int k=0;k<2*i+3;k++){
                System.out.print("*\t");
            }
            System.out.println();
        }
    }

    @Test
    public void name02() {

        int row = 8;

        for (int i=0;i< row;i++){
            for (int j=0;j<i;j++){
                System.out.print(" ");
            }
            for (int k=0;k<row-2*i;k++){
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void name03() {
        int row = 8;
        for (int i=0,k=row,m=0;i< row;i++){
            for(int l=m-i;l>0;l--){
                System.out.print("\t");
            }
            for(int j=k-i;j>0;j--){
                System.out.print("*\t");
            }
            if(i>row/2-1){
                k+=3;
            }else {
                k-=1;
            }
            if(i>row/2-1){
                m=row-1;
            }else {
                m+=2;
            }
            System.out.println();
        }
    }

    @Test
    public void test01() {
        System.out.println(System.currentTimeMillis());
    }

    @Test
    public void 京东金融发送测试() throws Exception {
        JSONObject json = new JSONObject();
        json.put("mobile","13501122436");

        String appId = "HRZR";
        //String param = AESUtils.AESEncode("pBGnFDKB4RXTIxlAADJcIrY2",json.toJSONString());
        String param = RiskEncryptUtils.encryptAES(json.toJSONString(),"pBGnFDKB4RXTIxlAADJcIrY2");
        String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String random = String.valueOf((int)((Math.random()*9+1)*10000));
        String sign = MD5Utils.md5(appId+param+timestamp+random,"tj7sXvqe");
        String type = "1";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("appId",appId);
        jsonObject.put("param",param);
        jsonObject.put("timestamp",timestamp);
        jsonObject.put("random",random);
        jsonObject.put("sign",sign);
        jsonObject.put("type",type);

        System.out.println(jsonObject.toJSONString());
    }

    @Test
    public void 京东金融结果解析测试() throws Exception {
        /*String decode = AESUtils.AESDecode("pBGnFDKB4RXTIxlAADJcIrY2", "I1LWWpkGICseAe5iKbOm2scaivrIwZO7A8ynP7YQM3e6O+73Wn8gKYMCehHaarnm+mkc3Moex/numcX59C0ONRWPStJOccaYOlSqctDecZc=");

        System.out.println("decode："+decode);*/
        //System.out.println(AESUtil.decrypt("I1LWWpkGICseAe5iKbOm2scaivrIwZO7A8ynP7YQM3e6O+73Wn8gKYMCehHaarnm+mkc3Moex/numcX59C0ONRWPStJOccaYOlSqctDecZc=","pBGnFDKB4RXTIxlAADJcIrY2"));

        /*String encode = AESUtils.AESEncode("1234", "987654321");
        System.out.println("encode: "+encode);
        String decode = AESUtil.decrypt(encode, "1234");
        System.out.println("decode: "+decode);*/
        System.out.println(RiskEncryptUtils.decryptAES("I1LWWpkGICseAe5iKbOm2scaivrIwZO7A8ynP7YQM3cjDszMEEsAh9R7XDYvdXyJbrAp831SEMfqlvwomnjIr+UyJJe8O38ED8fFmslIY/+Ff9CCymTm2hKOEy56oDPp","pBGnFDKB4RXTIxlAADJcIrY2"));
    }

    @Test
    public void 接口默认方法测试() {
        new LargeAnimalImpl().eat(LargeAnimal.mao());

    }

    @Test
    public void abcd() {
        System.out.println(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").format(LocalDateTime.now()));
    }
    


/**
 *
 ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`name` = '李雅'


 mobile = '1510558218' at line 5
 ### The error may exist in file [D:\admin\dev\workspace\fincloud\themis-sourcedata\themis-sourcedata\themis-sourcedata-infrastructure\out\production\resources\mybatis\TongDunDataMapper.xml]
 ### The error may involve defaultParameterMap
 ### The error occurred while setting parameters
 ### SQL: select id,content,task_no,id_card,`name`,mobile from t_tongdun_data          WHERE id_card = ?                                           `name` = ?                                           mobile = ?          order by id desc         limit 0,1
 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`name` = '李雅'


 mobile = '1510558218' at line 5
 ; bad SQL grammar []
 */
    @Test
    public void test100(){
        System.out.println("Hello World!");
    }
}